{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "pandas是基于Numpy构建的，这让以Numpy为中心的应用变得更加简单。  \n",
    "pandas主要包括三类数据结构，分别是：  \n",
    "\n",
    "Series：一维数组，与Numpy中的一维数组类似。二者与Python基本的数据结构List也很相近，其区别是：  \n",
    "List中的元素可以是不同的数据，而Array和Series中则只允许存储相同的数据类型，这样可以更有效地使用内存，提高运算效率。  \n",
    "\n",
    "DataFrame：二维的表格型数据结构。很多功能与R中的data.frame类似。可以将DataFrame理解为Series的容器。以下的内容主要以DataFrame为主。  \n",
    "\n",
    "Panel：三维的数组，可以理解为DataFrame的容器。 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Series(一维数组)\n",
    "由一维数据（各种Numpy类型数据），以及一组与之相关的标签数据（即索引）组成。  \n",
    "仅由一组数据即可产生最简单的Series，可以通过传递一个**列表**对象来创建一个Series."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1.0\n",
       "1    3.0\n",
       "2    5.0\n",
       "3    NaN\n",
       "4    6.0\n",
       "5    8.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "s = pd.Series([1,3,5,np.nan,6,8])\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=6, step=1)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取Series的索引\n",
    "s.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.,  3.,  5., nan,  6.,  8.])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看Series的值\n",
    "s.values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DataFrame(二维的表格型数据结构)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "DataFrame是一个表格型数据结构，它含有一组有序的列，每一列的数据类型都是相同的，而不同的列之间的数据类型可以不同。  \n",
    "DataFrame即有行索引也有列索引，可以被看作是由Series组成的字典（共用同一个索引）。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 通过传递list对象来创建DataFrame\n",
    "该DataFrame包括一个Numpy array,时间索引和列名："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2019-06-01', '2019-06-02', '2019-06-03', '2019-06-04',\n",
       "               '2019-06-05', '2019-06-06', '2019-06-07', '2019-06-08',\n",
       "               '2019-06-09', '2019-06-10'],\n",
       "              dtype='datetime64[ns]', freq='D')"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "dates = pd.date_range('20190601', periods=10)\n",
    "dates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.22296884, 8.29578388, 3.51668302, 3.72094834],\n",
       "       [0.74683475, 4.22612282, 2.13487895, 7.05740895],\n",
       "       [5.69405168, 9.65848238, 4.77411872, 5.25165601],\n",
       "       [1.62572182, 3.95054548, 1.39007117, 8.75943687],\n",
       "       [8.34999405, 5.00545424, 8.7383644 , 1.12479345],\n",
       "       [4.64066594, 4.07920904, 6.66689677, 7.80553418],\n",
       "       [8.80708674, 7.52491717, 9.15463262, 5.30801588],\n",
       "       [7.16946174, 5.57444779, 1.52809802, 9.98424474],\n",
       "       [4.22162087, 0.81264008, 0.19977169, 3.73620151],\n",
       "       [9.96639864, 1.64652798, 7.90449811, 8.72453258]])"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g = np.random.rand(10,4)*10 # 6行4列\n",
    "g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>1.222969</td>\n",
       "      <td>8.295784</td>\n",
       "      <td>3.516683</td>\n",
       "      <td>3.720948</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.746835</td>\n",
       "      <td>4.226123</td>\n",
       "      <td>2.134879</td>\n",
       "      <td>7.057409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>5.694052</td>\n",
       "      <td>9.658482</td>\n",
       "      <td>4.774119</td>\n",
       "      <td>5.251656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>1.625722</td>\n",
       "      <td>3.950545</td>\n",
       "      <td>1.390071</td>\n",
       "      <td>8.759437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.349994</td>\n",
       "      <td>5.005454</td>\n",
       "      <td>8.738364</td>\n",
       "      <td>1.124793</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>4.640666</td>\n",
       "      <td>4.079209</td>\n",
       "      <td>6.666897</td>\n",
       "      <td>7.805534</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>8.807087</td>\n",
       "      <td>7.524917</td>\n",
       "      <td>9.154633</td>\n",
       "      <td>5.308016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>7.169462</td>\n",
       "      <td>5.574448</td>\n",
       "      <td>1.528098</td>\n",
       "      <td>9.984245</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>4.221621</td>\n",
       "      <td>0.812640</td>\n",
       "      <td>0.199772</td>\n",
       "      <td>3.736202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>9.966399</td>\n",
       "      <td>1.646528</td>\n",
       "      <td>7.904498</td>\n",
       "      <td>8.724533</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  1.222969  8.295784  3.516683  3.720948\n",
       "2019-06-02  0.746835  4.226123  2.134879  7.057409\n",
       "2019-06-03  5.694052  9.658482  4.774119  5.251656\n",
       "2019-06-04  1.625722  3.950545  1.390071  8.759437\n",
       "2019-06-05  8.349994  5.005454  8.738364  1.124793\n",
       "2019-06-06  4.640666  4.079209  6.666897  7.805534\n",
       "2019-06-07  8.807087  7.524917  9.154633  5.308016\n",
       "2019-06-08  7.169462  5.574448  1.528098  9.984245\n",
       "2019-06-09  4.221621  0.812640  0.199772  3.736202\n",
       "2019-06-10  9.966399  1.646528  7.904498  8.724533"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list = ['open','high','low','close']\n",
    "df = pd.DataFrame(g, index=dates, columns=list)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 通过传递dict对象来创建DataFrame:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2013-01-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>test</td>\n",
       "      <td>foo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2013-01-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>train</td>\n",
       "      <td>foo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2013-01-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>test</td>\n",
       "      <td>foo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2013-01-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>train</td>\n",
       "      <td>foo</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A          B    C  D      E    F\n",
       "4  1.0 2013-01-01  1.0  3   test  foo\n",
       "5  1.0 2013-01-01  1.0  2  train  foo\n",
       "6  1.0 2013-01-01  1.0  3   test  foo\n",
       "7  1.0 2013-01-01  1.0  2  train  foo"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "df2 = pd.DataFrame({'A':1.,\n",
    "                  'B':pd.Timestamp('20130101'),\n",
    "                  'C':pd.Series(1, index=list(range(4,8)),dtype='float32'),\n",
    "                  'D':np.array([3,2]*2,dtype='int32'),\n",
    "                  'E':pd.Categorical(['test','train','test','train']),\n",
    "                  'F':'foo'})\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 7]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li = list(range(5,9,2))\n",
    "li"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 查看不同列的数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A           float64\n",
       "B    datetime64[ns]\n",
       "C           float32\n",
       "D             int32\n",
       "E          category\n",
       "F            object\n",
       "dtype: object"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**小技巧：**  \n",
    "使用Tab自动补全功能会自动识别所有的属性以及自定义的列。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 查看数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们以平台获取的数据为例进行讲解："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>9.111139</td>\n",
       "      <td>2.211407</td>\n",
       "      <td>6.988701</td>\n",
       "      <td>0.089185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.980347</td>\n",
       "      <td>6.708961</td>\n",
       "      <td>9.544625</td>\n",
       "      <td>6.291818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>7.926036</td>\n",
       "      <td>2.573801</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>3.128394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>6.839296</td>\n",
       "      <td>2.444304</td>\n",
       "      <td>9.148019</td>\n",
       "      <td>4.049135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.263982</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>3.926818</td>\n",
       "      <td>5.345961</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.519152</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>8.096648</td>\n",
       "      <td>7.738023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.460226</td>\n",
       "      <td>2.546845</td>\n",
       "      <td>4.604931</td>\n",
       "      <td>8.710222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>7.065063</td>\n",
       "      <td>6.087757</td>\n",
       "      <td>8.523341</td>\n",
       "      <td>8.257086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>6.290562</td>\n",
       "      <td>1.167303</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>9.578551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>3.847916</td>\n",
       "      <td>2.890099</td>\n",
       "      <td>8.978037</td>\n",
       "      <td>0.289279</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  9.111139  2.211407  6.988701  0.089185\n",
       "2019-06-02  9.980347  6.708961  9.544625  6.291818\n",
       "2019-06-03  7.926036  2.573801  3.188766  3.128394\n",
       "2019-06-04  6.839296  2.444304  9.148019  4.049135\n",
       "2019-06-05  8.263982  9.774338  3.926818  5.345961\n",
       "2019-06-06  0.519152  0.469483  8.096648  7.738023\n",
       "2019-06-07  3.460226  2.546845  4.604931  8.710222\n",
       "2019-06-08  7.065063  6.087757  8.523341  8.257086\n",
       "2019-06-09  6.290562  1.167303  9.980469  9.578551\n",
       "2019-06-10  3.847916  2.890099  8.978037  0.289279"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "dates = pd.date_range('20190601', periods=10)\n",
    "zreo_one_distribution = np.random.rand(10,4)*10 # 10行4列\n",
    "list = ['open','high','low','close']\n",
    "df2_4 = pd.DataFrame(zreo_one_distribution, index=dates, columns=list)\n",
    "df2_4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 查看前、后几条数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>9.111139</td>\n",
       "      <td>2.211407</td>\n",
       "      <td>6.988701</td>\n",
       "      <td>0.089185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.980347</td>\n",
       "      <td>6.708961</td>\n",
       "      <td>9.544625</td>\n",
       "      <td>6.291818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>7.926036</td>\n",
       "      <td>2.573801</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>3.128394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>6.839296</td>\n",
       "      <td>2.444304</td>\n",
       "      <td>9.148019</td>\n",
       "      <td>4.049135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.263982</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>3.926818</td>\n",
       "      <td>5.345961</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  9.111139  2.211407  6.988701  0.089185\n",
       "2019-06-02  9.980347  6.708961  9.544625  6.291818\n",
       "2019-06-03  7.926036  2.573801  3.188766  3.128394\n",
       "2019-06-04  6.839296  2.444304  9.148019  4.049135\n",
       "2019-06-05  8.263982  9.774338  3.926818  5.345961"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 默认查看前5条数据\n",
    "df2_4.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.519152</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>8.096648</td>\n",
       "      <td>7.738023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.460226</td>\n",
       "      <td>2.546845</td>\n",
       "      <td>4.604931</td>\n",
       "      <td>8.710222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>7.065063</td>\n",
       "      <td>6.087757</td>\n",
       "      <td>8.523341</td>\n",
       "      <td>8.257086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>6.290562</td>\n",
       "      <td>1.167303</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>9.578551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>3.847916</td>\n",
       "      <td>2.890099</td>\n",
       "      <td>8.978037</td>\n",
       "      <td>0.289279</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-06  0.519152  0.469483  8.096648  7.738023\n",
       "2019-06-07  3.460226  2.546845  4.604931  8.710222\n",
       "2019-06-08  7.065063  6.087757  8.523341  8.257086\n",
       "2019-06-09  6.290562  1.167303  9.980469  9.578551\n",
       "2019-06-10  3.847916  2.890099  8.978037  0.289279"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 默认查看后5条数据\n",
    "df2_4.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 显示索引、列和底层的numpy数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2019-06-01', '2019-06-02', '2019-06-03', '2019-06-04',\n",
       "               '2019-06-05', '2019-06-06', '2019-06-07', '2019-06-08',\n",
       "               '2019-06-09', '2019-06-10'],\n",
       "              dtype='datetime64[ns]', freq='D')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看索引\n",
    "df2_4.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['open', 'high', 'low', 'close'], dtype='object')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看列名\n",
    "df2_4.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[9.11113885, 2.2114069 , 6.98870128, 0.08918467],\n",
       "       [9.98034737, 6.7089608 , 9.54462534, 6.29181793],\n",
       "       [7.92603637, 2.57380143, 3.18876624, 3.128394  ],\n",
       "       [6.8392963 , 2.44430383, 9.14801926, 4.04913503],\n",
       "       [8.26398237, 9.77433817, 3.92681779, 5.34596071],\n",
       "       [0.51915168, 0.4694833 , 8.09664821, 7.73802256],\n",
       "       [3.46022622, 2.54684517, 4.60493116, 8.71022177],\n",
       "       [7.06506293, 6.08775654, 8.52334074, 8.25708575],\n",
       "       [6.29056198, 1.1673031 , 9.98046863, 9.57855051],\n",
       "       [3.84791649, 2.89009935, 8.97803723, 0.2892793 ]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看DataFrame的值\n",
    "df2_4.values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 对数据进行统计分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>10.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>10.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>6.330372</td>\n",
       "      <td>3.687430</td>\n",
       "      <td>7.298036</td>\n",
       "      <td>5.347765</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>2.911871</td>\n",
       "      <td>2.897292</td>\n",
       "      <td>2.499474</td>\n",
       "      <td>3.401427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.519152</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>0.089185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>4.458578</td>\n",
       "      <td>2.269631</td>\n",
       "      <td>5.200874</td>\n",
       "      <td>3.358579</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>6.952180</td>\n",
       "      <td>2.560323</td>\n",
       "      <td>8.309994</td>\n",
       "      <td>5.818889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>8.179496</td>\n",
       "      <td>5.288342</td>\n",
       "      <td>9.105524</td>\n",
       "      <td>8.127320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>9.980347</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>9.578551</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open       high        low      close\n",
       "count  10.000000  10.000000  10.000000  10.000000\n",
       "mean    6.330372   3.687430   7.298036   5.347765\n",
       "std     2.911871   2.897292   2.499474   3.401427\n",
       "min     0.519152   0.469483   3.188766   0.089185\n",
       "25%     4.458578   2.269631   5.200874   3.358579\n",
       "50%     6.952180   2.560323   8.309994   5.818889\n",
       "75%     8.179496   5.288342   9.105524   8.127320\n",
       "max     9.980347   9.774338   9.980469   9.578551"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# describe()函数用于快速对数据进行统计汇总\n",
    "df2_4.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 对数据的转置（transpose）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-06-01 00:00:00</th>\n",
       "      <th>2019-06-02 00:00:00</th>\n",
       "      <th>2019-06-03 00:00:00</th>\n",
       "      <th>2019-06-04 00:00:00</th>\n",
       "      <th>2019-06-05 00:00:00</th>\n",
       "      <th>2019-06-06 00:00:00</th>\n",
       "      <th>2019-06-07 00:00:00</th>\n",
       "      <th>2019-06-08 00:00:00</th>\n",
       "      <th>2019-06-09 00:00:00</th>\n",
       "      <th>2019-06-10 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>open</th>\n",
       "      <td>9.111139</td>\n",
       "      <td>9.980347</td>\n",
       "      <td>7.926036</td>\n",
       "      <td>6.839296</td>\n",
       "      <td>8.263982</td>\n",
       "      <td>0.519152</td>\n",
       "      <td>3.460226</td>\n",
       "      <td>7.065063</td>\n",
       "      <td>6.290562</td>\n",
       "      <td>3.847916</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>high</th>\n",
       "      <td>2.211407</td>\n",
       "      <td>6.708961</td>\n",
       "      <td>2.573801</td>\n",
       "      <td>2.444304</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>2.546845</td>\n",
       "      <td>6.087757</td>\n",
       "      <td>1.167303</td>\n",
       "      <td>2.890099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>low</th>\n",
       "      <td>6.988701</td>\n",
       "      <td>9.544625</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>9.148019</td>\n",
       "      <td>3.926818</td>\n",
       "      <td>8.096648</td>\n",
       "      <td>4.604931</td>\n",
       "      <td>8.523341</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>8.978037</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>close</th>\n",
       "      <td>0.089185</td>\n",
       "      <td>6.291818</td>\n",
       "      <td>3.128394</td>\n",
       "      <td>4.049135</td>\n",
       "      <td>5.345961</td>\n",
       "      <td>7.738023</td>\n",
       "      <td>8.710222</td>\n",
       "      <td>8.257086</td>\n",
       "      <td>9.578551</td>\n",
       "      <td>0.289279</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       2019-06-01  2019-06-02  2019-06-03  2019-06-04  2019-06-05  2019-06-06  \\\n",
       "open     9.111139    9.980347    7.926036    6.839296    8.263982    0.519152   \n",
       "high     2.211407    6.708961    2.573801    2.444304    9.774338    0.469483   \n",
       "low      6.988701    9.544625    3.188766    9.148019    3.926818    8.096648   \n",
       "close    0.089185    6.291818    3.128394    4.049135    5.345961    7.738023   \n",
       "\n",
       "       2019-06-07  2019-06-08  2019-06-09  2019-06-10  \n",
       "open     3.460226    7.065063    6.290562    3.847916  \n",
       "high     2.546845    6.087757    1.167303    2.890099  \n",
       "low      4.604931    8.523341    9.980469    8.978037  \n",
       "close    8.710222    8.257086    9.578551    0.289279  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方法1\n",
    "df2_4.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-06-01 00:00:00</th>\n",
       "      <th>2019-06-02 00:00:00</th>\n",
       "      <th>2019-06-03 00:00:00</th>\n",
       "      <th>2019-06-04 00:00:00</th>\n",
       "      <th>2019-06-05 00:00:00</th>\n",
       "      <th>2019-06-06 00:00:00</th>\n",
       "      <th>2019-06-07 00:00:00</th>\n",
       "      <th>2019-06-08 00:00:00</th>\n",
       "      <th>2019-06-09 00:00:00</th>\n",
       "      <th>2019-06-10 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>open</th>\n",
       "      <td>9.111139</td>\n",
       "      <td>9.980347</td>\n",
       "      <td>7.926036</td>\n",
       "      <td>6.839296</td>\n",
       "      <td>8.263982</td>\n",
       "      <td>0.519152</td>\n",
       "      <td>3.460226</td>\n",
       "      <td>7.065063</td>\n",
       "      <td>6.290562</td>\n",
       "      <td>3.847916</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>high</th>\n",
       "      <td>2.211407</td>\n",
       "      <td>6.708961</td>\n",
       "      <td>2.573801</td>\n",
       "      <td>2.444304</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>2.546845</td>\n",
       "      <td>6.087757</td>\n",
       "      <td>1.167303</td>\n",
       "      <td>2.890099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>low</th>\n",
       "      <td>6.988701</td>\n",
       "      <td>9.544625</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>9.148019</td>\n",
       "      <td>3.926818</td>\n",
       "      <td>8.096648</td>\n",
       "      <td>4.604931</td>\n",
       "      <td>8.523341</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>8.978037</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>close</th>\n",
       "      <td>0.089185</td>\n",
       "      <td>6.291818</td>\n",
       "      <td>3.128394</td>\n",
       "      <td>4.049135</td>\n",
       "      <td>5.345961</td>\n",
       "      <td>7.738023</td>\n",
       "      <td>8.710222</td>\n",
       "      <td>8.257086</td>\n",
       "      <td>9.578551</td>\n",
       "      <td>0.289279</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       2019-06-01  2019-06-02  2019-06-03  2019-06-04  2019-06-05  2019-06-06  \\\n",
       "open     9.111139    9.980347    7.926036    6.839296    8.263982    0.519152   \n",
       "high     2.211407    6.708961    2.573801    2.444304    9.774338    0.469483   \n",
       "low      6.988701    9.544625    3.188766    9.148019    3.926818    8.096648   \n",
       "close    0.089185    6.291818    3.128394    4.049135    5.345961    7.738023   \n",
       "\n",
       "       2019-06-07  2019-06-08  2019-06-09  2019-06-10  \n",
       "open     3.460226    7.065063    6.290562    3.847916  \n",
       "high     2.546845    6.087757    1.167303    2.890099  \n",
       "low      4.604931    8.523341    9.980469    8.978037  \n",
       "close    8.710222    8.257086    9.578551    0.289279  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方法2\n",
    "df2_4.T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 按轴进行排序\n",
    "axis=0  x轴；  \n",
    "axis=1  y轴；    \n",
    "sort_index()是对索引名称进行升降序排列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>2.513136</td>\n",
       "      <td>0.771591</td>\n",
       "      <td>7.750666</td>\n",
       "      <td>3.538462</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>4.763476</td>\n",
       "      <td>2.904257</td>\n",
       "      <td>4.026242</td>\n",
       "      <td>7.618623</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>3.548905</td>\n",
       "      <td>4.175340</td>\n",
       "      <td>1.419139</td>\n",
       "      <td>3.931544</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>7.205219</td>\n",
       "      <td>6.263434</td>\n",
       "      <td>0.105530</td>\n",
       "      <td>9.947598</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>4.474814</td>\n",
       "      <td>4.952045</td>\n",
       "      <td>9.142510</td>\n",
       "      <td>0.648304</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>2.510234</td>\n",
       "      <td>7.868712</td>\n",
       "      <td>1.731533</td>\n",
       "      <td>2.551494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>9.679115</td>\n",
       "      <td>5.273317</td>\n",
       "      <td>0.876872</td>\n",
       "      <td>7.620799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>2.500585</td>\n",
       "      <td>1.540693</td>\n",
       "      <td>0.165465</td>\n",
       "      <td>1.100909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>9.395937</td>\n",
       "      <td>0.987736</td>\n",
       "      <td>6.468363</td>\n",
       "      <td>9.029495</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>8.412780</td>\n",
       "      <td>0.608826</td>\n",
       "      <td>5.770001</td>\n",
       "      <td>3.568287</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  2.513136  0.771591  7.750666  3.538462\n",
       "2019-06-02  4.763476  2.904257  4.026242  7.618623\n",
       "2019-06-03  3.548905  4.175340  1.419139  3.931544\n",
       "2019-06-04  7.205219  6.263434  0.105530  9.947598\n",
       "2019-06-05  4.474814  4.952045  9.142510  0.648304\n",
       "2019-06-06  2.510234  7.868712  1.731533  2.551494\n",
       "2019-06-07  9.679115  5.273317  0.876872  7.620799\n",
       "2019-06-08  2.500585  1.540693  0.165465  1.100909\n",
       "2019-06-09  9.395937  0.987736  6.468363  9.029495\n",
       "2019-06-10  8.412780  0.608826  5.770001  3.568287"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>9.111139</td>\n",
       "      <td>2.211407</td>\n",
       "      <td>6.988701</td>\n",
       "      <td>0.089185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.980347</td>\n",
       "      <td>6.708961</td>\n",
       "      <td>9.544625</td>\n",
       "      <td>6.291818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>7.926036</td>\n",
       "      <td>2.573801</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>3.128394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>6.839296</td>\n",
       "      <td>2.444304</td>\n",
       "      <td>9.148019</td>\n",
       "      <td>4.049135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.263982</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>3.926818</td>\n",
       "      <td>5.345961</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.519152</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>8.096648</td>\n",
       "      <td>7.738023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.460226</td>\n",
       "      <td>2.546845</td>\n",
       "      <td>4.604931</td>\n",
       "      <td>8.710222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>7.065063</td>\n",
       "      <td>6.087757</td>\n",
       "      <td>8.523341</td>\n",
       "      <td>8.257086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>6.290562</td>\n",
       "      <td>1.167303</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>9.578551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>3.847916</td>\n",
       "      <td>2.890099</td>\n",
       "      <td>8.978037</td>\n",
       "      <td>0.289279</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  9.111139  2.211407  6.988701  0.089185\n",
       "2019-06-02  9.980347  6.708961  9.544625  6.291818\n",
       "2019-06-03  7.926036  2.573801  3.188766  3.128394\n",
       "2019-06-04  6.839296  2.444304  9.148019  4.049135\n",
       "2019-06-05  8.263982  9.774338  3.926818  5.345961\n",
       "2019-06-06  0.519152  0.469483  8.096648  7.738023\n",
       "2019-06-07  3.460226  2.546845  4.604931  8.710222\n",
       "2019-06-08  7.065063  6.087757  8.523341  8.257086\n",
       "2019-06-09  6.290562  1.167303  9.980469  9.578551\n",
       "2019-06-10  3.847916  2.890099  8.978037  0.289279"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis=0等于axis='index'\n",
    "df2_4.sort_index(axis=0,ascending=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>3.847916</td>\n",
       "      <td>2.890099</td>\n",
       "      <td>8.978037</td>\n",
       "      <td>0.289279</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>6.290562</td>\n",
       "      <td>1.167303</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>9.578551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>7.065063</td>\n",
       "      <td>6.087757</td>\n",
       "      <td>8.523341</td>\n",
       "      <td>8.257086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.460226</td>\n",
       "      <td>2.546845</td>\n",
       "      <td>4.604931</td>\n",
       "      <td>8.710222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.519152</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>8.096648</td>\n",
       "      <td>7.738023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.263982</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>3.926818</td>\n",
       "      <td>5.345961</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>6.839296</td>\n",
       "      <td>2.444304</td>\n",
       "      <td>9.148019</td>\n",
       "      <td>4.049135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>7.926036</td>\n",
       "      <td>2.573801</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>3.128394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.980347</td>\n",
       "      <td>6.708961</td>\n",
       "      <td>9.544625</td>\n",
       "      <td>6.291818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>9.111139</td>\n",
       "      <td>2.211407</td>\n",
       "      <td>6.988701</td>\n",
       "      <td>0.089185</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-10  3.847916  2.890099  8.978037  0.289279\n",
       "2019-06-09  6.290562  1.167303  9.980469  9.578551\n",
       "2019-06-08  7.065063  6.087757  8.523341  8.257086\n",
       "2019-06-07  3.460226  2.546845  4.604931  8.710222\n",
       "2019-06-06  0.519152  0.469483  8.096648  7.738023\n",
       "2019-06-05  8.263982  9.774338  3.926818  5.345961\n",
       "2019-06-04  6.839296  2.444304  9.148019  4.049135\n",
       "2019-06-03  7.926036  2.573801  3.188766  3.128394\n",
       "2019-06-02  9.980347  6.708961  9.544625  6.291818\n",
       "2019-06-01  9.111139  2.211407  6.988701  0.089185"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ascending=True(升序排列)；ascending=False(降序排列)\n",
    "df2_4.sort_index(axis=0,ascending=False) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>open</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>0.089185</td>\n",
       "      <td>2.211407</td>\n",
       "      <td>6.988701</td>\n",
       "      <td>9.111139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>6.291818</td>\n",
       "      <td>6.708961</td>\n",
       "      <td>9.544625</td>\n",
       "      <td>9.980347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>3.128394</td>\n",
       "      <td>2.573801</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>7.926036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>4.049135</td>\n",
       "      <td>2.444304</td>\n",
       "      <td>9.148019</td>\n",
       "      <td>6.839296</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>5.345961</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>3.926818</td>\n",
       "      <td>8.263982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>7.738023</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>8.096648</td>\n",
       "      <td>0.519152</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>8.710222</td>\n",
       "      <td>2.546845</td>\n",
       "      <td>4.604931</td>\n",
       "      <td>3.460226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>8.257086</td>\n",
       "      <td>6.087757</td>\n",
       "      <td>8.523341</td>\n",
       "      <td>7.065063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>9.578551</td>\n",
       "      <td>1.167303</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>6.290562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>0.289279</td>\n",
       "      <td>2.890099</td>\n",
       "      <td>8.978037</td>\n",
       "      <td>3.847916</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               close      high       low      open\n",
       "2019-06-01  0.089185  2.211407  6.988701  9.111139\n",
       "2019-06-02  6.291818  6.708961  9.544625  9.980347\n",
       "2019-06-03  3.128394  2.573801  3.188766  7.926036\n",
       "2019-06-04  4.049135  2.444304  9.148019  6.839296\n",
       "2019-06-05  5.345961  9.774338  3.926818  8.263982\n",
       "2019-06-06  7.738023  0.469483  8.096648  0.519152\n",
       "2019-06-07  8.710222  2.546845  4.604931  3.460226\n",
       "2019-06-08  8.257086  6.087757  8.523341  7.065063\n",
       "2019-06-09  9.578551  1.167303  9.980469  6.290562\n",
       "2019-06-10  0.289279  2.890099  8.978037  3.847916"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis=1等于axis='columns'\n",
    "df2_4.sort_index(axis=1,ascending=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>low</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>9.111139</td>\n",
       "      <td>6.988701</td>\n",
       "      <td>2.211407</td>\n",
       "      <td>0.089185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.980347</td>\n",
       "      <td>9.544625</td>\n",
       "      <td>6.708961</td>\n",
       "      <td>6.291818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>7.926036</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>2.573801</td>\n",
       "      <td>3.128394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>6.839296</td>\n",
       "      <td>9.148019</td>\n",
       "      <td>2.444304</td>\n",
       "      <td>4.049135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.263982</td>\n",
       "      <td>3.926818</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>5.345961</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.519152</td>\n",
       "      <td>8.096648</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>7.738023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.460226</td>\n",
       "      <td>4.604931</td>\n",
       "      <td>2.546845</td>\n",
       "      <td>8.710222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>7.065063</td>\n",
       "      <td>8.523341</td>\n",
       "      <td>6.087757</td>\n",
       "      <td>8.257086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>6.290562</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>1.167303</td>\n",
       "      <td>9.578551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>3.847916</td>\n",
       "      <td>8.978037</td>\n",
       "      <td>2.890099</td>\n",
       "      <td>0.289279</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open       low      high     close\n",
       "2019-06-01  9.111139  6.988701  2.211407  0.089185\n",
       "2019-06-02  9.980347  9.544625  6.708961  6.291818\n",
       "2019-06-03  7.926036  3.188766  2.573801  3.128394\n",
       "2019-06-04  6.839296  9.148019  2.444304  4.049135\n",
       "2019-06-05  8.263982  3.926818  9.774338  5.345961\n",
       "2019-06-06  0.519152  8.096648  0.469483  7.738023\n",
       "2019-06-07  3.460226  4.604931  2.546845  8.710222\n",
       "2019-06-08  7.065063  8.523341  6.087757  8.257086\n",
       "2019-06-09  6.290562  9.980469  1.167303  9.578551\n",
       "2019-06-10  3.847916  8.978037  2.890099  0.289279"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_4.sort_index(axis=1,ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 按值进行排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.519152</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>8.096648</td>\n",
       "      <td>7.738023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.460226</td>\n",
       "      <td>2.546845</td>\n",
       "      <td>4.604931</td>\n",
       "      <td>8.710222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>3.847916</td>\n",
       "      <td>2.890099</td>\n",
       "      <td>8.978037</td>\n",
       "      <td>0.289279</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>6.290562</td>\n",
       "      <td>1.167303</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>9.578551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>6.839296</td>\n",
       "      <td>2.444304</td>\n",
       "      <td>9.148019</td>\n",
       "      <td>4.049135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>7.065063</td>\n",
       "      <td>6.087757</td>\n",
       "      <td>8.523341</td>\n",
       "      <td>8.257086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>7.926036</td>\n",
       "      <td>2.573801</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>3.128394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.263982</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>3.926818</td>\n",
       "      <td>5.345961</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>9.111139</td>\n",
       "      <td>2.211407</td>\n",
       "      <td>6.988701</td>\n",
       "      <td>0.089185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.980347</td>\n",
       "      <td>6.708961</td>\n",
       "      <td>9.544625</td>\n",
       "      <td>6.291818</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-06  0.519152  0.469483  8.096648  7.738023\n",
       "2019-06-07  3.460226  2.546845  4.604931  8.710222\n",
       "2019-06-10  3.847916  2.890099  8.978037  0.289279\n",
       "2019-06-09  6.290562  1.167303  9.980469  9.578551\n",
       "2019-06-04  6.839296  2.444304  9.148019  4.049135\n",
       "2019-06-08  7.065063  6.087757  8.523341  8.257086\n",
       "2019-06-03  7.926036  2.573801  3.188766  3.128394\n",
       "2019-06-05  8.263982  9.774338  3.926818  5.345961\n",
       "2019-06-01  9.111139  2.211407  6.988701  0.089185\n",
       "2019-06-02  9.980347  6.708961  9.544625  6.291818"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对open列的数据进行升序排列\n",
    "df2_4.sort_values(by='open',ascending=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.980347</td>\n",
       "      <td>6.708961</td>\n",
       "      <td>9.544625</td>\n",
       "      <td>6.291818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>9.111139</td>\n",
       "      <td>2.211407</td>\n",
       "      <td>6.988701</td>\n",
       "      <td>0.089185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.263982</td>\n",
       "      <td>9.774338</td>\n",
       "      <td>3.926818</td>\n",
       "      <td>5.345961</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>7.926036</td>\n",
       "      <td>2.573801</td>\n",
       "      <td>3.188766</td>\n",
       "      <td>3.128394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>7.065063</td>\n",
       "      <td>6.087757</td>\n",
       "      <td>8.523341</td>\n",
       "      <td>8.257086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>6.839296</td>\n",
       "      <td>2.444304</td>\n",
       "      <td>9.148019</td>\n",
       "      <td>4.049135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>6.290562</td>\n",
       "      <td>1.167303</td>\n",
       "      <td>9.980469</td>\n",
       "      <td>9.578551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>3.847916</td>\n",
       "      <td>2.890099</td>\n",
       "      <td>8.978037</td>\n",
       "      <td>0.289279</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.460226</td>\n",
       "      <td>2.546845</td>\n",
       "      <td>4.604931</td>\n",
       "      <td>8.710222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.519152</td>\n",
       "      <td>0.469483</td>\n",
       "      <td>8.096648</td>\n",
       "      <td>7.738023</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-02  9.980347  6.708961  9.544625  6.291818\n",
       "2019-06-01  9.111139  2.211407  6.988701  0.089185\n",
       "2019-06-05  8.263982  9.774338  3.926818  5.345961\n",
       "2019-06-03  7.926036  2.573801  3.188766  3.128394\n",
       "2019-06-08  7.065063  6.087757  8.523341  8.257086\n",
       "2019-06-04  6.839296  2.444304  9.148019  4.049135\n",
       "2019-06-09  6.290562  1.167303  9.980469  9.578551\n",
       "2019-06-10  3.847916  2.890099  8.978037  0.289279\n",
       "2019-06-07  3.460226  2.546845  4.604931  8.710222\n",
       "2019-06-06  0.519152  0.469483  8.096648  7.738023"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对open列的数据进行降序排列\n",
    "df2_4.sort_values(by='open',ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 选择数据\n",
    "### 通过下标选择数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "df['open']，df.open两个语句是等效的，都是返回 df 名称为 open 列的数据，返回一个 Series。  \n",
    "df[0:3], df['2017-06-01':'2017-06-05']下标索引选取的是 DataFrame 的记录。   \n",
    "\n",
    "与 List 相同 DataFrame 的下标也是从0开始，区间索引的话，为一个左闭右开的区间，即[0：3]选取的为0-2三条记录。  \n",
    "还可以用起始的索引名称和结束索引名称选取数据,如：df['a':'b']。  \n",
    "\n",
    "需要注意的是使用起始索引名称和结束索引名称时，也会包含结束索引的数据。以上两种方式返回的都是DataFrame。  \n",
    "具体看下方示例： "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.925297</td>\n",
       "      <td>3.986475</td>\n",
       "      <td>7.200105</td>\n",
       "      <td>3.319409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.931925</td>\n",
       "      <td>0.096879</td>\n",
       "      <td>5.133140</td>\n",
       "      <td>0.403244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.777795</td>\n",
       "      <td>8.999843</td>\n",
       "      <td>5.374552</td>\n",
       "      <td>2.534591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>4.907680</td>\n",
       "      <td>0.466965</td>\n",
       "      <td>2.603271</td>\n",
       "      <td>0.127082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>4.393066</td>\n",
       "      <td>0.135219</td>\n",
       "      <td>6.429140</td>\n",
       "      <td>4.298915</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>8.145999</td>\n",
       "      <td>4.034788</td>\n",
       "      <td>6.914401</td>\n",
       "      <td>2.436211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>7.646782</td>\n",
       "      <td>4.718518</td>\n",
       "      <td>7.367690</td>\n",
       "      <td>0.232069</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>0.347201</td>\n",
       "      <td>9.249291</td>\n",
       "      <td>5.469980</td>\n",
       "      <td>9.117035</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>3.929119</td>\n",
       "      <td>7.544853</td>\n",
       "      <td>4.511056</td>\n",
       "      <td>5.686305</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>4.090959</td>\n",
       "      <td>4.804137</td>\n",
       "      <td>8.619014</td>\n",
       "      <td>9.046639</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.925297  3.986475  7.200105  3.319409\n",
       "2019-06-02  0.931925  0.096879  5.133140  0.403244\n",
       "2019-06-03  2.777795  8.999843  5.374552  2.534591\n",
       "2019-06-04  4.907680  0.466965  2.603271  0.127082\n",
       "2019-06-05  4.393066  0.135219  6.429140  4.298915\n",
       "2019-06-06  8.145999  4.034788  6.914401  2.436211\n",
       "2019-06-07  7.646782  4.718518  7.367690  0.232069\n",
       "2019-06-08  0.347201  9.249291  5.469980  9.117035\n",
       "2019-06-09  3.929119  7.544853  4.511056  5.686305\n",
       "2019-06-10  4.090959  4.804137  8.619014  9.046639"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "dates = pd.date_range('20190601', periods=10)\n",
    "zreo_one_distribution = np.random.rand(10,4)*10 # 10行4列\n",
    "list = ['open','high','low','close']\n",
    "df2_5 = pd.DataFrame(zreo_one_distribution, index=dates, columns=list)\n",
    "df2_5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 选择一列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-06-01    6.925297\n",
       "2019-06-02    0.931925\n",
       "2019-06-03    2.777795\n",
       "2019-06-04    4.907680\n",
       "2019-06-05    4.393066\n",
       "2019-06-06    8.145999\n",
       "2019-06-07    7.646782\n",
       "2019-06-08    0.347201\n",
       "2019-06-09    3.929119\n",
       "2019-06-10    4.090959\n",
       "Freq: D, Name: open, dtype: float64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择open列的数据\n",
    "df2_5['open'] "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 选择多列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.925297</td>\n",
       "      <td>3.319409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.931925</td>\n",
       "      <td>0.403244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.777795</td>\n",
       "      <td>2.534591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>4.907680</td>\n",
       "      <td>0.127082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>4.393066</td>\n",
       "      <td>4.298915</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>8.145999</td>\n",
       "      <td>2.436211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>7.646782</td>\n",
       "      <td>0.232069</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>0.347201</td>\n",
       "      <td>9.117035</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>3.929119</td>\n",
       "      <td>5.686305</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>4.090959</td>\n",
       "      <td>9.046639</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open     close\n",
       "2019-06-01  6.925297  3.319409\n",
       "2019-06-02  0.931925  0.403244\n",
       "2019-06-03  2.777795  2.534591\n",
       "2019-06-04  4.907680  0.127082\n",
       "2019-06-05  4.393066  4.298915\n",
       "2019-06-06  8.145999  2.436211\n",
       "2019-06-07  7.646782  0.232069\n",
       "2019-06-08  0.347201  9.117035\n",
       "2019-06-09  3.929119  5.686305\n",
       "2019-06-10  4.090959  9.046639"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_5[['open','close']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 选择多行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.925297</td>\n",
       "      <td>3.986475</td>\n",
       "      <td>7.200105</td>\n",
       "      <td>3.319409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.931925</td>\n",
       "      <td>0.096879</td>\n",
       "      <td>5.133140</td>\n",
       "      <td>0.403244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.777795</td>\n",
       "      <td>8.999843</td>\n",
       "      <td>5.374552</td>\n",
       "      <td>2.534591</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.925297  3.986475  7.200105  3.319409\n",
       "2019-06-02  0.931925  0.096879  5.133140  0.403244\n",
       "2019-06-03  2.777795  8.999843  5.374552  2.534591"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 位置索引\n",
    "df2_5[0:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.925297</td>\n",
       "      <td>3.986475</td>\n",
       "      <td>7.200105</td>\n",
       "      <td>3.319409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.931925</td>\n",
       "      <td>0.096879</td>\n",
       "      <td>5.133140</td>\n",
       "      <td>0.403244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.777795</td>\n",
       "      <td>8.999843</td>\n",
       "      <td>5.374552</td>\n",
       "      <td>2.534591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>4.907680</td>\n",
       "      <td>0.466965</td>\n",
       "      <td>2.603271</td>\n",
       "      <td>0.127082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>4.393066</td>\n",
       "      <td>0.135219</td>\n",
       "      <td>6.429140</td>\n",
       "      <td>4.298915</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.925297  3.986475  7.200105  3.319409\n",
       "2019-06-02  0.931925  0.096879  5.133140  0.403244\n",
       "2019-06-03  2.777795  8.999843  5.374552  2.534591\n",
       "2019-06-04  4.907680  0.466965  2.603271  0.127082\n",
       "2019-06-05  4.393066  0.135219  6.429140  4.298915"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 标签索引\n",
    "df2_5['2019-06-01':'2019-06-05']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 通过标签选取数据\n",
    "- df.loc[行标签,列标签]  \n",
    "- df.loc['a':'b'] #选取 ab 两行数据  \n",
    "- df.loc[:,'open'] #选取 open 列的数据   \n",
    "\n",
    "df.loc 的第一个参数是行标签，第二个参数为列标签（可选参数，默认为所有列标签），两个参数既可以是列表也可以是单个字符。如果两个参数都为列表则返回的是 DataFrame，否则，则为 Series。\n",
    "\n",
    "PS：loc为location的缩写。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6.925296504971658"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取行交列的单个数值\n",
    "df2_5.loc['2019-06-01','open']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.925297</td>\n",
       "      <td>3.986475</td>\n",
       "      <td>7.200105</td>\n",
       "      <td>3.319409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.931925</td>\n",
       "      <td>0.096879</td>\n",
       "      <td>5.133140</td>\n",
       "      <td>0.403244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.777795</td>\n",
       "      <td>8.999843</td>\n",
       "      <td>5.374552</td>\n",
       "      <td>2.534591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>4.907680</td>\n",
       "      <td>0.466965</td>\n",
       "      <td>2.603271</td>\n",
       "      <td>0.127082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>4.393066</td>\n",
       "      <td>0.135219</td>\n",
       "      <td>6.429140</td>\n",
       "      <td>4.298915</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>8.145999</td>\n",
       "      <td>4.034788</td>\n",
       "      <td>6.914401</td>\n",
       "      <td>2.436211</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.925297  3.986475  7.200105  3.319409\n",
       "2019-06-02  0.931925  0.096879  5.133140  0.403244\n",
       "2019-06-03  2.777795  8.999843  5.374552  2.534591\n",
       "2019-06-04  4.907680  0.466965  2.603271  0.127082\n",
       "2019-06-05  4.393066  0.135219  6.429140  4.298915\n",
       "2019-06-06  8.145999  4.034788  6.914401  2.436211"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#选取区间行数据\n",
    "df2_5.loc['2019-06-01':'2019-06-06']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-06-01    6.925297\n",
       "2019-06-02    0.931925\n",
       "2019-06-03    2.777795\n",
       "2019-06-04    4.907680\n",
       "2019-06-05    4.393066\n",
       "2019-06-06    8.145999\n",
       "2019-06-07    7.646782\n",
       "2019-06-08    0.347201\n",
       "2019-06-09    3.929119\n",
       "2019-06-10    4.090959\n",
       "Freq: D, Name: open, dtype: float64"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#选取所有行的 open 列的数据\n",
    "df2_5.loc[:,'open']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-06-01    6.925297\n",
       "2019-06-02    0.931925\n",
       "2019-06-03    2.777795\n",
       "2019-06-04    4.907680\n",
       "2019-06-05    4.393066\n",
       "2019-06-06    8.145999\n",
       "Freq: D, Name: open, dtype: float64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取区间行交指定列的数据\n",
    "df2_5.loc['2019-06-01':'2019-06-06','open']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 通过位置选取数据\n",
    "- df.iloc[行位置,列位置]\n",
    "- df.iloc[1,1] #选取第二行，第二列的值，返回的为单个值\n",
    "- df.iloc[[0,2],:] #选取第一行及第三行的数据\n",
    "- df.iloc[0:2,:] #选取第一行到第三行（不包含）的数据\n",
    "- df.iloc[:,1] #选取所有记录的第二列的值，返回的为一个Series\n",
    "- df.iloc[1,:] #选取第一行数据，返回的为一个Series\n",
    "\n",
    "PS：iloc 则为 integer & location 的缩写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>2.594537</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>6.708913</td>\n",
       "      <td>0.041023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>1.922037</td>\n",
       "      <td>2.904484</td>\n",
       "      <td>0.060149</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>7.494163</td>\n",
       "      <td>5.166609</td>\n",
       "      <td>4.801551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>4.949363</td>\n",
       "      <td>9.777113</td>\n",
       "      <td>5.421154</td>\n",
       "      <td>7.677120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>6.186702</td>\n",
       "      <td>9.163937</td>\n",
       "      <td>4.745684</td>\n",
       "      <td>6.745426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>7.759351</td>\n",
       "      <td>5.381608</td>\n",
       "      <td>6.000137</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>6.769660</td>\n",
       "      <td>1.953244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>5.151098</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>1.421423</td>\n",
       "      <td>1.413568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>5.589647</td>\n",
       "      <td>9.442603</td>\n",
       "      <td>5.525858</td>\n",
       "      <td>6.506602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>5.673073</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>5.594822</td>\n",
       "      <td>2.483338</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-01  2.594537  9.624780  6.708913  0.041023\n",
       "2019-01-02  1.922037  2.904484  0.060149  9.858212\n",
       "2019-01-03  9.404449  7.494163  5.166609  4.801551\n",
       "2019-01-04  4.949363  9.777113  5.421154  7.677120\n",
       "2019-01-05  6.186702  9.163937  4.745684  6.745426\n",
       "2019-01-06  7.759351  5.381608  6.000137  8.779823\n",
       "2019-01-07  8.148540  9.652254  6.769660  1.953244\n",
       "2019-01-08  5.151098  8.146486  1.421423  1.413568\n",
       "2019-01-09  5.589647  9.442603  5.525858  6.506602\n",
       "2019-01-10  5.673073  9.184724  5.594822  2.483338"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "dates = pd.date_range('20190101', periods=10)\n",
    "distribution = np.random.rand(10,4)*10 # 10行4列\n",
    "list = ['open','high','low','close']\n",
    "df2_5 = pd.DataFrame(distribution, index=dates, columns=list)\n",
    "df2_5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.904484318213465"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取第2行交第2列的值，返回单个值\n",
    "df2_5.iloc[1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>2.594537</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>6.708913</td>\n",
       "      <td>0.041023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>7.494163</td>\n",
       "      <td>5.166609</td>\n",
       "      <td>4.801551</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-01  2.594537  9.624780  6.708913  0.041023\n",
       "2019-01-03  9.404449  7.494163  5.166609  4.801551"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取第1行、第3行交所有列的数据（非区间）\n",
    "df2_5.iloc[[0,2],:] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-01-01    9.624780\n",
       "2019-01-02    2.904484\n",
       "2019-01-03    7.494163\n",
       "2019-01-04    9.777113\n",
       "2019-01-05    9.163937\n",
       "2019-01-06    5.381608\n",
       "2019-01-07    9.652254\n",
       "2019-01-08    8.146486\n",
       "2019-01-09    9.442603\n",
       "2019-01-10    9.184724\n",
       "Freq: D, Name: high, dtype: float64"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取所有行交第2列的值，返回的为一个Series\n",
    "df2_5.iloc[:,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "open     1.922037\n",
       "high     2.904484\n",
       "low      0.060149\n",
       "close    9.858212\n",
       "Name: 2019-01-02 00:00:00, dtype: float64"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取第2行交所有列的数据，返回的为一个Series\n",
    "df2_5.iloc[1,:] "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用ix获取数据\n",
    "更广义的切片方式是使用.ix。  \n",
    "它会自动根据给出的索引类型判断是使用**位置**还是**标签**进行切片。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "5.048632660493169"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_5.ix[1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>0.833175</td>\n",
       "      <td>4.292431</td>\n",
       "      <td>5.267151</td>\n",
       "      <td>7.623721</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>1.578833</td>\n",
       "      <td>5.048633</td>\n",
       "      <td>5.303261</td>\n",
       "      <td>6.885764</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>2.099065</td>\n",
       "      <td>9.819080</td>\n",
       "      <td>1.942463</td>\n",
       "      <td>2.817264</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>6.976177</td>\n",
       "      <td>7.707388</td>\n",
       "      <td>3.072416</td>\n",
       "      <td>5.986185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>0.146856</td>\n",
       "      <td>1.714931</td>\n",
       "      <td>9.314118</td>\n",
       "      <td>8.710319</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>4.501978</td>\n",
       "      <td>7.462104</td>\n",
       "      <td>6.252740</td>\n",
       "      <td>1.616744</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-01  0.833175  4.292431  5.267151  7.623721\n",
       "2019-01-02  1.578833  5.048633  5.303261  6.885764\n",
       "2019-01-03  2.099065  9.819080  1.942463  2.817264\n",
       "2019-01-04  6.976177  7.707388  3.072416  5.986185\n",
       "2019-01-05  0.146856  1.714931  9.314118  8.710319\n",
       "2019-01-06  4.501978  7.462104  6.252740  1.616744"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_5.ix['2019-01-01':'2019-01-06']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:2: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1.9424628126608412"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 位置索引+位置索引\n",
    "df2_5.ix['2019-01-03','low']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:2: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "6.8857637965972165"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 位置索引+标签索引\n",
    "df2_5.ix[1,'close']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:2: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2.0990649246754134"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 标签索引+位置索引\n",
    "df2_5.ix['2019-01-03',0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 通过逻辑指针进行数据切片\n",
    "df[逻辑条件]\n",
    "- df[df.one >= 2] #单个逻辑条件\n",
    "- df[(df.one >=1 ) & (df.one < 3) ] #多个逻辑条件组合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>2.594537</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>6.708913</td>\n",
       "      <td>0.041023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>1.922037</td>\n",
       "      <td>2.904484</td>\n",
       "      <td>0.060149</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>7.494163</td>\n",
       "      <td>5.166609</td>\n",
       "      <td>4.801551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>4.949363</td>\n",
       "      <td>9.777113</td>\n",
       "      <td>5.421154</td>\n",
       "      <td>7.677120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>6.186702</td>\n",
       "      <td>9.163937</td>\n",
       "      <td>4.745684</td>\n",
       "      <td>6.745426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>7.759351</td>\n",
       "      <td>5.381608</td>\n",
       "      <td>6.000137</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>6.769660</td>\n",
       "      <td>1.953244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>5.151098</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>1.421423</td>\n",
       "      <td>1.413568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>5.589647</td>\n",
       "      <td>9.442603</td>\n",
       "      <td>5.525858</td>\n",
       "      <td>6.506602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>5.673073</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>5.594822</td>\n",
       "      <td>2.483338</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-01  2.594537  9.624780  6.708913  0.041023\n",
       "2019-01-02  1.922037  2.904484  0.060149  9.858212\n",
       "2019-01-03  9.404449  7.494163  5.166609  4.801551\n",
       "2019-01-04  4.949363  9.777113  5.421154  7.677120\n",
       "2019-01-05  6.186702  9.163937  4.745684  6.745426\n",
       "2019-01-06  7.759351  5.381608  6.000137  8.779823\n",
       "2019-01-07  8.148540  9.652254  6.769660  1.953244\n",
       "2019-01-08  5.151098  8.146486  1.421423  1.413568\n",
       "2019-01-09  5.589647  9.442603  5.525858  6.506602\n",
       "2019-01-10  5.673073  9.184724  5.594822  2.483338"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>7.494163</td>\n",
       "      <td>5.166609</td>\n",
       "      <td>4.801551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>7.759351</td>\n",
       "      <td>5.381608</td>\n",
       "      <td>6.000137</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>6.769660</td>\n",
       "      <td>1.953244</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-03  9.404449  7.494163  5.166609  4.801551\n",
       "2019-01-06  7.759351  5.381608  6.000137  8.779823\n",
       "2019-01-07  8.148540  9.652254  6.769660  1.953244"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 筛选出open大于6.8的数据\n",
    "df2_5[df2_5.open>6.8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>7.494163</td>\n",
       "      <td>5.166609</td>\n",
       "      <td>4.801551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>6.769660</td>\n",
       "      <td>1.953244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>5.151098</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>1.421423</td>\n",
       "      <td>1.413568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>5.673073</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>5.594822</td>\n",
       "      <td>2.483338</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-03  9.404449  7.494163  5.166609  4.801551\n",
       "2019-01-07  8.148540  9.652254  6.769660  1.953244\n",
       "2019-01-08  5.151098  8.146486  1.421423  1.413568\n",
       "2019-01-10  5.673073  9.184724  5.594822  2.483338"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 筛选出open大于2.8，并且close<6的数据\n",
    "df2_5[(df2_5.open>2.8)&(df2_5.close<6)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.777113</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.163937</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>NaN</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.442603</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high  low     close\n",
       "2019-01-01       NaN  9.624780  NaN       NaN\n",
       "2019-01-02       NaN       NaN  NaN  9.858212\n",
       "2019-01-03  9.404449       NaN  NaN       NaN\n",
       "2019-01-04       NaN  9.777113  NaN       NaN\n",
       "2019-01-05       NaN  9.163937  NaN       NaN\n",
       "2019-01-06       NaN       NaN  NaN  8.779823\n",
       "2019-01-07  8.148540  9.652254  NaN       NaN\n",
       "2019-01-08       NaN  8.146486  NaN       NaN\n",
       "2019-01-09       NaN  9.442603  NaN       NaN\n",
       "2019-01-10       NaN  9.184724  NaN       NaN"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 显示特定条件的数据\n",
    "df2_5[df2_5>8]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以看到df2_5中小于8的数都变成了NaN。  \n",
    "\n",
    "下面我们接着把小于8的数赋值为0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.777113</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.163937</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.442603</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high  low     close\n",
       "2019-01-01  0.000000  9.624780  0.0  0.000000\n",
       "2019-01-02  0.000000  0.000000  0.0  9.858212\n",
       "2019-01-03  9.404449  0.000000  0.0  0.000000\n",
       "2019-01-04  0.000000  9.777113  0.0  0.000000\n",
       "2019-01-05  0.000000  9.163937  0.0  0.000000\n",
       "2019-01-06  0.000000  0.000000  0.0  8.779823\n",
       "2019-01-07  8.148540  9.652254  0.0  0.000000\n",
       "2019-01-08  0.000000  8.146486  0.0  0.000000\n",
       "2019-01-09  0.000000  9.442603  0.0  0.000000\n",
       "2019-01-10  0.000000  9.184724  0.0  0.000000"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 把特定条件的数据赋值为某特定数\n",
    "df2_5[df2_5<8] = 0\n",
    "df2_5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用isin()方法过滤指定列中的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.777113</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.163937</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.442603</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high  low     close\n",
       "2019-01-01  0.000000  9.624780  0.0  0.000000\n",
       "2019-01-02  0.000000  0.000000  0.0  9.858212\n",
       "2019-01-03  9.404449  0.000000  0.0  0.000000\n",
       "2019-01-04  0.000000  9.777113  0.0  0.000000\n",
       "2019-01-05  0.000000  9.163937  0.0  0.000000\n",
       "2019-01-06  0.000000  0.000000  0.0  8.779823\n",
       "2019-01-07  8.148540  9.652254  0.0  0.000000\n",
       "2019-01-08  0.000000  8.146486  0.0  0.000000\n",
       "2019-01-09  0.000000  9.442603  0.0  0.000000\n",
       "2019-01-10  0.000000  9.184724  0.0  0.000000"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open  high  low     close\n",
       "2019-01-02  0.000000   0.0  0.0  9.858212\n",
       "2019-01-03  9.404449   0.0  0.0  0.000000\n",
       "2019-01-06  0.000000   0.0  0.0  8.779823"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取 high 列中数为 0 和 9 的数。\n",
    "df2_5[df2_5['high'].isin([0.0,9.652254])]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Panel"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "平台get_price,如果是多只股票，则返回pandas.Panel对象。  \n",
    "可通过panel[列标,行标,股票代码]获取数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[9.17058255e+00, 3.33288896e+00, 2.11073970e+00, 5.83124359e-01],\n",
       "        [7.14377380e+00, 4.35061753e+00, 4.83786329e+00, 1.33864196e+00],\n",
       "        [2.40518759e+00, 5.38936438e+00, 7.90854050e+00, 1.04793030e+00],\n",
       "        [2.74410552e+00, 3.93381745e+00, 2.18544107e-01, 5.68690265e+00],\n",
       "        [3.90191837e+00, 2.71524607e+00, 7.01980556e+00, 2.00076435e+00],\n",
       "        [7.91304217e+00, 7.27773302e+00, 1.72190591e+00, 5.15888726e-01],\n",
       "        [7.85200625e+00, 2.86564475e+00, 9.61629552e+00, 9.62642646e+00],\n",
       "        [6.09522587e+00, 9.48314485e+00, 5.13044105e+00, 5.82713123e+00],\n",
       "        [5.86401415e+00, 7.25242193e+00, 8.30539948e+00, 5.93246072e+00],\n",
       "        [5.26405281e-01, 7.58923892e+00, 2.78053014e+00, 2.79060412e+00]],\n",
       "\n",
       "       [[1.75562521e-01, 5.40826387e+00, 9.72818512e+00, 6.88943680e-03],\n",
       "        [9.01564571e+00, 1.13993243e+00, 6.96232577e+00, 9.58431881e+00],\n",
       "        [8.76032625e+00, 3.59015549e+00, 1.36210554e+00, 2.15452294e+00],\n",
       "        [6.46024079e-01, 3.90882376e+00, 8.02790283e-01, 1.32917216e+00],\n",
       "        [1.62073026e+00, 6.37910235e+00, 1.96176109e+00, 2.91636070e+00],\n",
       "        [9.96203445e+00, 8.53319589e+00, 8.90074321e+00, 1.44720248e+00],\n",
       "        [9.36570727e+00, 3.21630856e+00, 5.43426673e+00, 2.84604627e+00],\n",
       "        [4.36962995e+00, 4.83541970e+00, 4.68512119e+00, 2.46356518e+00],\n",
       "        [5.74778144e+00, 3.11250122e+00, 2.51489603e+00, 4.99328091e-01],\n",
       "        [2.93849928e+00, 3.63918704e-01, 6.07531699e+00, 1.10398462e+00]]])"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np \n",
    "\n",
    "dates = pd.date_range('20190601', periods=10)\n",
    "zreo_one_distributes_2 = np.random.rand(2,10,4)*10 # 2个数组10行4列\n",
    "zreo_one_distributes_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2963: FutureWarning: \n",
      "Panel is deprecated and will be removed in a future version.\n",
      "The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method\n",
      "Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.\n",
      "Pandas provides a `.to_xarray()` method to help automate this conversion.\n",
      "\n",
      "  exec(code_obj, self.user_global_ns, self.user_ns)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<class 'pandas.core.panel.Panel'>\n",
       "Dimensions: 2 (items) x 10 (major_axis) x 4 (minor_axis)\n",
       "Items axis: 0 to 1\n",
       "Major_axis axis: 0 to 9\n",
       "Minor_axis axis: 0 to 3"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list = ['open','high','low','close']\n",
    "p3 = pd.Panel(zreo_one_distributes_2)\n",
    "p3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9.170583</td>\n",
       "      <td>3.332889</td>\n",
       "      <td>2.110740</td>\n",
       "      <td>0.583124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7.143774</td>\n",
       "      <td>4.350618</td>\n",
       "      <td>4.837863</td>\n",
       "      <td>1.338642</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.405188</td>\n",
       "      <td>5.389364</td>\n",
       "      <td>7.908540</td>\n",
       "      <td>1.047930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2.744106</td>\n",
       "      <td>3.933817</td>\n",
       "      <td>0.218544</td>\n",
       "      <td>5.686903</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.901918</td>\n",
       "      <td>2.715246</td>\n",
       "      <td>7.019806</td>\n",
       "      <td>2.000764</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7.913042</td>\n",
       "      <td>7.277733</td>\n",
       "      <td>1.721906</td>\n",
       "      <td>0.515889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7.852006</td>\n",
       "      <td>2.865645</td>\n",
       "      <td>9.616296</td>\n",
       "      <td>9.626426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>6.095226</td>\n",
       "      <td>9.483145</td>\n",
       "      <td>5.130441</td>\n",
       "      <td>5.827131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5.864014</td>\n",
       "      <td>7.252422</td>\n",
       "      <td>8.305399</td>\n",
       "      <td>5.932461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.526405</td>\n",
       "      <td>7.589239</td>\n",
       "      <td>2.780530</td>\n",
       "      <td>2.790604</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3\n",
       "0  9.170583  3.332889  2.110740  0.583124\n",
       "1  7.143774  4.350618  4.837863  1.338642\n",
       "2  2.405188  5.389364  7.908540  1.047930\n",
       "3  2.744106  3.933817  0.218544  5.686903\n",
       "4  3.901918  2.715246  7.019806  2.000764\n",
       "5  7.913042  7.277733  1.721906  0.515889\n",
       "6  7.852006  2.865645  9.616296  9.626426\n",
       "7  6.095226  9.483145  5.130441  5.827131\n",
       "8  5.864014  7.252422  8.305399  5.932461\n",
       "9  0.526405  7.589239  2.780530  2.790604"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 展示第1层\n",
    "p3[0,:,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.175563</td>\n",
       "      <td>5.408264</td>\n",
       "      <td>9.728185</td>\n",
       "      <td>0.006889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9.015646</td>\n",
       "      <td>1.139932</td>\n",
       "      <td>6.962326</td>\n",
       "      <td>9.584319</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8.760326</td>\n",
       "      <td>3.590155</td>\n",
       "      <td>1.362106</td>\n",
       "      <td>2.154523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.646024</td>\n",
       "      <td>3.908824</td>\n",
       "      <td>0.802790</td>\n",
       "      <td>1.329172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.620730</td>\n",
       "      <td>6.379102</td>\n",
       "      <td>1.961761</td>\n",
       "      <td>2.916361</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>9.962034</td>\n",
       "      <td>8.533196</td>\n",
       "      <td>8.900743</td>\n",
       "      <td>1.447202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9.365707</td>\n",
       "      <td>3.216309</td>\n",
       "      <td>5.434267</td>\n",
       "      <td>2.846046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>4.369630</td>\n",
       "      <td>4.835420</td>\n",
       "      <td>4.685121</td>\n",
       "      <td>2.463565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5.747781</td>\n",
       "      <td>3.112501</td>\n",
       "      <td>2.514896</td>\n",
       "      <td>0.499328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2.938499</td>\n",
       "      <td>0.363919</td>\n",
       "      <td>6.075317</td>\n",
       "      <td>1.103985</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3\n",
       "0  0.175563  5.408264  9.728185  0.006889\n",
       "1  9.015646  1.139932  6.962326  9.584319\n",
       "2  8.760326  3.590155  1.362106  2.154523\n",
       "3  0.646024  3.908824  0.802790  1.329172\n",
       "4  1.620730  6.379102  1.961761  2.916361\n",
       "5  9.962034  8.533196  8.900743  1.447202\n",
       "6  9.365707  3.216309  5.434267  2.846046\n",
       "7  4.369630  4.835420  4.685121  2.463565\n",
       "8  5.747781  3.112501  2.514896  0.499328\n",
       "9  2.938499  0.363919  6.075317  1.103985"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出第2层\n",
    "p3[1,:,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2.405188</td>\n",
       "      <td>8.760326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5.389364</td>\n",
       "      <td>3.590155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7.908540</td>\n",
       "      <td>1.362106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.047930</td>\n",
       "      <td>2.154523</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1\n",
       "0  2.405188  8.760326\n",
       "1  5.389364  3.590155\n",
       "2  7.908540  1.362106\n",
       "3  1.047930  2.154523"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出两层叠放数据中，索引位置为3的数据\n",
    "p3[:,2,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.583124</td>\n",
       "      <td>0.006889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.338642</td>\n",
       "      <td>9.584319</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.047930</td>\n",
       "      <td>2.154523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5.686903</td>\n",
       "      <td>1.329172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2.000764</td>\n",
       "      <td>2.916361</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.515889</td>\n",
       "      <td>1.447202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9.626426</td>\n",
       "      <td>2.846046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>5.827131</td>\n",
       "      <td>2.463565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5.932461</td>\n",
       "      <td>0.499328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2.790604</td>\n",
       "      <td>1.103985</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1\n",
       "0  0.583124  0.006889\n",
       "1  1.338642  9.584319\n",
       "2  1.047930  2.154523\n",
       "3  5.686903  1.329172\n",
       "4  2.000764  2.916361\n",
       "5  0.515889  1.447202\n",
       "6  9.626426  2.846046\n",
       "7  5.827131  2.463565\n",
       "8  5.932461  0.499328\n",
       "9  2.790604  1.103985"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出两层中，索引位置为3的数据\n",
    "p3[:,:,3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Panel的操作与DataFrame的操作基本相同。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "336px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
